package anthology.daily_question._25_01;
//https://leetcode.cn/problems/find-closest-number-to-zero/description/?envType=daily-question&envId=2025-01-20
public class _2239找到最接近0的数字 {
    class Solution {
        public int findClosestNumber(int[] nums) {
            int tmp = nums[0];
            for(int i : nums){
                if(Math.abs(i) < Math.abs(tmp)){
                    tmp = i;
                }else if(Math.abs(i) == Math.abs(tmp)){
                    tmp = Math.max(i,tmp);
                }
            }
            return tmp;
        }
    }
    class Solution2 {
        public int findClosestNumber(int[] nums) {
            int ans = nums[0];
            for (int x : nums) {
                if (Math.abs(x) < Math.abs(ans) || Math.abs(x) == Math.abs(ans) && x > 0) {
                    ans = x;
                }
            }
            return ans;
        }
    }
}
